//我的帖子
Vue.component('my_post', {
	template: '<div class="my_post_list">\
						<li class="type_title">我的帖子</li>\
						<!--帖子列表-->\
						<div class="community_news">\
							<div class="content" @click="go_detail(item)" v-for="(item,index) in forum">\
								<!--上半部分-->\
								<div>\
									<img :src="item.HeadImage" alt="" />\
									<div class="my_flex my_flex_between">\
										<span>{{item.Title}}</span>\
										<img @click.stop="del(index)" src="imgs/community/del.png" alt="" />\
									</div>\
								</div>\
								<div>\
									<span>{{item.CreateTimeText}}</span>\
								</div>\
								<div>\
									<span>{{item.ContentShort}}</span>\
								</div>\
								<div>\
									<!--循环图片,返回数所中没有图片-->\
								</div>\
								<!--下半部分-->\
								<div class="icons">\
									<li class="my_flex my_flex_center"><img :src="item.LikeOrUnlike ? \'imgs/community/liked.png\' : \'imgs/community/like.png\' " />{{item.Like}}</li>\
									<li class="my_flex my_flex_center"><img :src="item.LikeOrUnlike==false ? \'imgs/community/unliked.png\' : \'imgs/community/unlike.png\' " alt="" />{{item.Unlike}}</li>\
									<li class="my_flex my_flex_center"><img src="imgs/community/back.png" alt="" />{{item.ReplyCount}}</li>\
								</div>\
							</div>\
							<div v-if="forum.length<1"><p class="text-center nocontent">暂无内容</p></div>\
							<change-page v-if="forum.length>0" :current_page="page.pageIndex" :page_size="page.pageSize" :page_total="page.pageTotal" @page-change="getPageForumsForApp"></change-page>\
						</div>\
					</div>',
	data: function() {
		return {
			url: {
				getPageForumsForApp: '/api/Forum/GetPageMyCommentsForApp', //帖子分页
				del: '/api/Forum/DeleteMyForum',
			},
			forum: [], //我的帖子
			page: {
				pageIndex: 1,
				pageSize: 20,
				pageTotal: 0
			}
		}
	},
	mounted: function() {
		this.getPageForumsForApp(this.page.pageIndex, this.page.pageSize);
	},
	methods: {
		//获取帖子
		getPageForumsForApp: function(curPage, pageSize) {
			var that = this;
			var data = {
				PageIndex: curPage,
				PageSize: pageSize
			};
			globalData.ajaxPost(this.url.getPageForumsForApp, data, function(res) {
				var d = res.data;
				if(d == null)
					return;
				globalData.utils.page(that, curPage, res.count);
				for(var i = 0; i < d.length; i++) {
					d[i].HeadImage=globalData.utils.imagePrefix(d[i].HeadImage);
				}
				that.forum = d;
				console.log(d)
			})
		},
		//删除帖子
		del: function(index) {
			var that = this;
			var d = this.forum[index];
			var data = {
				ID: d.ID
			};
			globalData.ajaxPost(this.url.del, data, function(res) {
				if(res.suc) {
					globalData.utils.alert("删除成功");
					that.forum.splice(index, 1);
				}
			})
		},
		//去详情页
		go_detail: function(item) {
			var obj = {
				id:item.ID
			}
			var url = "forum_datail.html"
			globalData.utils.setUrl(url,obj)
		}
	}
});